// import { ElMessage } from "element-plus";
// import { useI18n } from "vue-i18n";
import { onMounted } from "vue";
export let getDay = (val: string) => {
  const currentTime = new Date();
  const year = currentTime.getFullYear();
  const month = currentTime.getMonth() + 1; // 月份从0开始，因此需要加1
  const day = currentTime.getDate();
  const hours = currentTime.getHours();
  const minutes = currentTime.getMinutes();
  const seconds = currentTime.getSeconds();
  // return year + val + month + val + day;
  // return (
  //   year + val + month + val + day + " " + hours + ":" + minutes + ":" + seconds
  // );
};
export let getAllTime = (val: string) => {
  const currentTime = new Date();
  const year = currentTime.getFullYear();
  const month = currentTime.getMonth() + 1; // 月份从0开始，因此需要加1
  const day = currentTime.getDate();
  const hours = currentTime.getHours();
  const minutes = currentTime.getMinutes();
  const seconds = currentTime.getSeconds();
  // return year + val + month + val + day;
  return (
    year +
    val +
    (month >= 10 ? month : "0" + month) +
    val +
    (day >= 10 ? day : "0" + day) +
    " " +
    (hours >= 10 ? hours : "0" + hours) +
    ":" +
    (minutes >= 10 ? minutes : "0" + minutes) +
    ":" +
    (seconds >= 10 ? seconds : "0" + seconds)
  );
};
// const { t } = useI18n();
export let getTime = () => {
  const currentTime = new Date();
  const hours = currentTime.getHours();
  const minutes = currentTime.getMinutes();
  const seconds = currentTime.getSeconds();

  // return (
  //   year + val + month + val + day
  // );
  return hours + ":" + minutes + ":" + seconds;
};
export let $openPage = async (path?: string, query?: {}) => {
  if (path == "/commonPage") {
    let time: any = null;
    time = await setTimeout(() => {
      navigateTo({ path, query });
      clearTimeout(time);
    }, 200);
    return;
  }

  await navigateTo({ path, query });
};
export let $back = () => {
  let router = useRouter();
  router.back();
};
export const formatDateTime = (dateTime: any) => {
  const date = new Date(dateTime);
  const year = date.getFullYear();
  const month =
    date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1;
  const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  const hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  const minutes =
    date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  const seconds =
    date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}`;
};

export let $dot = (data: any = "") => {
  let str: string = "0.00";
  if (data == 0 || data == "" || data == undefined || data == null) return str;
  str = (Number(data) / 100).toFixed(2).toString();
  return str.includes(".") ? str : str + ".00";
};

// export async function copyToClipboard(text: any) {
//   if (process.client) {
//     try {
//       console.log( navigator,navigator.clipboard,'navigator.clipboard');

//       await navigator.clipboard.writeText(text);
//       console.log('Text copied to clipboard');
//       // 这里可以添加复制成功的提示或者操作
//     } catch (err) {
//       console.error('Failed to copy text: ', err);
//       // 这里可以添加复制失败的提示或者操作
//     }
//     // let tmpTextField: any = document.createElement("textarea");
//     // tmpTextField.textContent = text;
//     // tmpTextField.setAttribute("style", "position:absolute; right:200%;");
//     // document.body.appendChild(tmpTextField);
//     // tmpTextField.select();
//     // tmpTextField.setSelectionRange(0, 99999); /*For mobile devices*/
//     // document.execCommand("copy");
//     // const nuxtApp: any = useNuxtApp();
//     // console.log(nuxtApp.vueApp);
//     // if (nuxtApp.vueApp?.__VUE_I18N__) {
//     //   let { t } = nuxtApp.vueApp["__VUE_I18N__"]["global"];
//     //   ElMessage({
//     //     message: t("language.commontips.copysuccess"),
//     //     type: "success",
//     //     duration: 1000,
//     //   });
//     // }
//     // navigator.clipboard.writeText(text);

//     // tmpTextField.remove();
//     if (text) {
//       // await $copyText(text)
//     } else {
//       // ElMessage({
//       //   message: t("language.commontips.copysempty"),
//       //   type: "error",
//       // });
//     }
//   }
// }

//本地存储方案一
// export let hasToken =  () => {
//   let istoken = useToken();
//   let loginopen = useLoginopen();
//   loginopen.value = true;
//   let flag = istoken.value != "" && istoken.value  && istoken.value  != null;
//   loginopen.value = !flag;
//   return flag;
// };
//本地存储方案二pinia
// const store = useStore()

// let istoken=computed(()=>store.token)
// export let hasToken =  () => {
//   let flag = istoken.value != "" && istoken.value  && istoken.value  != null;
//   if(!flag){
//     store.loginopen=true
//   }
//   return flag;
// };

export let $tips = (
  val: string,
  type: any = "success",
  duration: number = 1000,
  onClose?: any
) => {
  if (process.client) {
    const nuxtApp: any = useNuxtApp();

    let { t }: { t: any } = nuxtApp.vueApp["__VUE_I18N__"]["global"];
    // console.log(t(val), "t(val)");

    ElMessage({
      message: t(val),
      type,
      duration,
      onClose,
    });
  }
};
